package de.mafr.jsystest.matchers;

import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;

import de.mafr.jsystest.ws.Response;


/**
 * Checks if a response has the given status code.
 * 
 * We use <?> or otherwise the type system would require
 * a cast inside of assertThat().
 */
public class HasStatus extends TypeSafeMatcher<Response<?>> {
	private final int statusCode;

	public HasStatus(int statusCode) {
		this.statusCode = statusCode;
	}

	@Override
	public boolean matchesSafely(Response<?> actual) {
		return actual.getStatusCode() == statusCode;
	}

	public void describeTo(Description description) {
		description.appendText("status code ").appendValue(statusCode);
	}
	
	@Factory
	public static Matcher<Response<?>> status(int statusCode) {
		return new HasStatus(statusCode);
	}
}
